// 表单验证
let form = layui.form;

form.verify({ // 指定规则名和对应的验证规则
    password: [ // 密码
        /^[\S]{6,10}$/,
        '密码是6到10位, 不能有空格'
    ],
    diff: function (value) {
        return value === $('.oldPwd').val() && '两次密码不能一致'
    },
    same: function (value) {
        return value !== $('.newPwd').val() && '两次密码要一致'
    }
})


// http://api-breakingnews-web.itheima.net
// /my/updatepwd
// =====================立即提交=====================
$('form').on('submit', function (e) {
    // 阻止默认事件跳转
    e.preventDefault()

    const data = $(this).serialize()

    axios({
        method: 'post',
        url: ' http://api-breakingnews-web.itheima.net/my/updatepwd',
        data,
        headers: {
            'Authorization': localStorage.getItem('token')
        }
    }).then((res) => {
        // console.log(res)
        if (res.data.status === 1) {
            layer.msg(res.data.message)
        } else {
            localStorage.removeItem('token')

            window.parent.location.href = '/login.html'
        }
    })



})